package maxHeap;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/19 7:38
 */
public class HeapSort {
    private HeapSort(){}

    public static <E extends Comparable<E>> void sort(E[] data){
        MaxHeap<E> maxHeap = new MaxHeap<>();
        for(E e: data){
            maxHeap.add(e);
        }

        //因为要从小到大排序，所以最大堆中
//        我们倒序放置值
        for (int i = data.length-1;i>=0;i--){
            data[i] = maxHeap.extractMax();
        }
    }


    public static void main(String[] args) {
        int n = 1000000;
        Integer[] arr = ArrayGenerator.generateRandomArray(n,n);
        SortHelper.sortTest("HeapSort",arr);
    }
}
